package com.tramy.cnpush.receiver;

import android.content.Context;
import android.util.Log;

import com.tramy.cnpush.utils.CallBackUtils;
import com.xiaomi.mipush.sdk.ErrorCode;
import com.xiaomi.mipush.sdk.MiPushClient;
import com.xiaomi.mipush.sdk.MiPushCommandMessage;
import com.xiaomi.mipush.sdk.PushMessageReceiver;

import java.util.List;

public class MiPushMessageReceiver extends PushMessageReceiver {

    @Override
    public void onReceiveRegisterResult(Context context,
                                        MiPushCommandMessage message) {
        String command = message.getCommand();
        List<String> arguments = message.getCommandArguments();
        String cmdArg1 = ((arguments != null && arguments.size() > 0) ? arguments.get(0) : null);
        String cmdArg2 = ((arguments != null && arguments.size() > 1) ? arguments.get(1) : null);
        if (MiPushClient.COMMAND_REGISTER.equals(command)) {
            if (message.getResultCode() == ErrorCode.SUCCESS) {
                CallBackUtils.consumeCallback(cmdArg1);
            }else {
                CallBackUtils.consumeCallback("");
                Log.e("XiaomiPush", message.getResultCode() + "," + message.getReason());
            }
        }
    }

}
